// pages/epi_5/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    token: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      var that = this
      wx.login({
          success(res){
              if (res.code) {
                  
                  wx.request({
                      url: 'http://47.109.143.70/for224/login',
                      method: 'post',
                      header: {'content-type':'application/json'},
                      data: {
                          code: res.code
                      },
                      success(res){
                          that.setData({
                              token: res.data.token
                            })
                      },
                      fail(res){
                          console.log(res.message)
                      }
                  })
              }
          }
      })
  },

  run(e){
      switch(e.currentTarget.id){
            case 'sS':
                wx.setStorage({
                    key: 'token',
                    data: this.data.token,
                    success(res){
                        wx.showToast({
                            icon: 'success',
                            title: '存储成功'
                        })
                    }
                })
                break
            case 'gS':
                wx.getStorage({
                    key: 'token',
                    success(res){
                        console.log(res.data)
                    }
                })
                break
            case 'rS':
                console.log('rs')
                break
            case 'gSI':
                console.log('gSI')
                break
      }
  },
})